<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <script src="__STATIC__/js/jquery.js"></script>
    <script src="__STATIC__/layui/layui.js"></script>
    <script type="text/javascript" src="__STATIC__/x-admin/js/xadmin.js"></script>
    <link rel="stylesheet" href="__STATIC__/x-admin/css/font.css">
    <link rel="stylesheet" href="__STATIC__/x-admin/css/xadmin.css">
    <link rel="stylesheet" href="__STATIC__/layui/css/layui.css">
</head>
<body>
<div style="width: 300px">
    <form class="layui-form" action="" name="grade_update" onclick="return false" id="grade_update" style="padding-top: 5px">
        <input type="hidden" name="id" value="{$info->id}">
        <div class="layui-form-item">
            <label class="layui-form-label">年级</label>
            <div class="layui-input-block">
                <input type="text" name="grade" value="{$info->grade_title}" placeholder="年级" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">所属类别</label>
            <div class="layui-input-block">
                <input type="number" name="type" value="{$info->type}" placeholder="所属类别，比如:1" autocomplete="off" lay-verify="type" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">类别名称</label>
            <div class="layui-input-block">
                <input type="text" name="grade_name" value="{$info->grade_name}" placeholder="所属类别，比如:小学" autocomplete="off" lay-verify="grade_name" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" id="update" lay-submit lay-filter="*">立即修改</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>
</div>
</body>
<script>
    layui.use(['form', 'layedit', 'laydate'],function () {
        var form = layui.form;
        form.verify({
            grade: function(value){
                if(value.length == 0){
                    return '年级请输入至少1个字符';
                }
            },
            type:function (value) {
                var reg = /^(-|\+)?\d+$/ ;
                if(!reg.test(value)){
                    return '类别必须是数字'
                }
            },
            grade_name:function (value) {
                if(value.length == 0){
                    return '类别名称请输入至少1个字符';
                }
            }
        });
        form.on('submit(*)', function() {
            $.ajax({
                data:$("#grade_update").serialize(),
                url:"{:url('/grade/update')}",
                type:'post',
                dataType:"json",
                success:function(res){
                    if(res.code){
                        layer.msg(res.msg,{icon:1,time:2000},function(){
                            var index = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(index);
                        });
                    }else{
                        layer.msg(res.msg,{icon:5,time:2000});
                    }
                }
            });
        });
    })
</script>
</html>